﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinCustControl
{
    
    public partial class UPanel : Panel
    {
        public UPanel()
        {
            InitializeComponent();

            //圆角面板控件样式设置
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);//忽略窗口消息 减少闪烁
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);//绘制到缓冲区 减少闪烁
            SetStyle(ControlStyles.UserPaint, true);//控件由其自身而不是操作系统绘制
            SetStyle(ControlStyles.ResizeRedraw, true);//控件调整大小时重绘
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);//支持透明背景

        }


        //设置背景色1默认为灰色
        private Color bgColor=Color.LightGray;
        /// <summary>
        /// 背景色1(渐变颜色1)
        /// </summary>
        [DefaultValue(typeof(Color), "LightGray"),Description("控件背景色1")]
        public Color BgColor
        {
            get { return bgColor; }
            set { bgColor = value; 
                //Refresh();//立即重绘(及时执行)
                Invalidate();//引发重绘,不会立即
            }
        }




        //设置背景色2默认为灰色
        private Color bgColor2 = Color.Transparent;
        /// <summary>
        /// 背景色2(渐变颜色2)
        /// </summary>
        [DefaultValue(typeof(Color), "Transparent"), Description("控件背景色2")]
        public Color BgColor2
        {
            get { return bgColor2; }
            set
            {
                bgColor2 = value;
                //Refresh();//立即重绘(及时执行)
                Invalidate();//引发重绘,不会立即
            }
        }




        //设置边框色
        private Color borderColor = Color.Gray;
        /// <summary>
        /// 边框色
        /// </summary>
        [DefaultValue(typeof(Color), "Gray"), Description("控件边框色")]
        public Color BorderColor
        {
            get { return borderColor; }
            set
            {
                borderColor = value;
                //Refresh();//立即重绘(及时执行)
                Invalidate();//引发重绘,不会立即
            }
        }




        //设置边框粗细
        private int borderWidth =0;
        /// <summary>
        /// 边框粗细
        /// </summary>
        [DefaultValue(typeof(int), "0"), Description("控件边框粗细")]
        public int BorderWidth
        {
            get { return borderWidth; }
            set
            {
                borderWidth = value;
                //Refresh();//立即重绘(及时执行)
                Invalidate();//引发重绘,不会立即
            }
        }



        //设置边框圆角半径
        private int radius = 5;
        /// <summary>
        /// 边框圆角半径
        /// </summary>
        [DefaultValue(typeof(int), "5"), Description("控件边框圆角半径")]
        public int Radius
        {
            get { return radius; }
            set
            {
                radius = value;
                //Refresh();//立即重绘(及时执行)
                Invalidate();//引发重绘,不会立即
            }
        }



        //设置背景渐变模式
        private LinearGradientMode gradientModel = LinearGradientMode.Vertical;
        /// <summary>
        /// 背景渐变模式
        /// </summary>
        [DefaultValue(typeof(LinearGradientMode), "Vertical"), Description("控件背景渐变模式")]
        public LinearGradientMode GradientModel
        {
            get { return gradientModel; }
            set
            {
                gradientModel = value;
                //Refresh();//立即重绘(及时执行)
                Invalidate();//引发重绘,不会立即
            }
        }



        Rectangle r;//绘制区域
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);


        }

    }
}
